<template>
 <div>
    <el-form-item :label="+(index )+'、视频：'">
      <my-ldyUpload
        :data="video"
        @reUrlData="getVideoUrl"
        @delData="delUrl"
        ref="upload"
        ></my-ldyUpload>
    </el-form-item>
    <el-form-item label="视频链接：" v-if="src">
      <el-button type="primary" size="mini"><a target="_blank" :href="src">点击查看</a></el-button>
      <el-button
        size="mini"
        type="primary"
        v-clipboard:copy="src"
        v-clipboard:success="onCopy"
        v-clipboard:error="onError"
      >
        复制链接
      </el-button>
    </el-form-item>
   <div v-if="src">
     <el-button type="primary" @click="sure()" style="float:right;">确定</el-button>
   </div>
 </div>
</template>
<script>
  import ldyUpload from "@/views/market/ldy/ldyUpload.vue";
export default {
  props: ["index"],
  data() {
    return {
      flag: false,
      src: '',
      video:{
        type: 3,
        limit: 1,
        tips:'上传视频MP4文件，宽750',
        num:'',
      },
      videoData:{
         "index":"",
         "module_type": "3",//1顶部图,2单图，3视频，4轮播，
         "resource_url": "",
       }

    };
  },

  components: {
    "my-ldyUpload": ldyUpload,
  },
  mounted() {
    this.video.num=this.index;
    this.videoData.resource_url="";

  },
  methods: {
    getVideoUrl(data) {
       //console.log(data);
       this.videoData.resource_url=data;
       this.videoData.index=this.index;
      this.src=data;
    },
    delUrl(){
      this.src="";
    },
    // 确定
    sure() {
      this.$emit("getUrl", this.videoData);
      this.$nextTick(() => {
        //console.log(this.$refs.upload.fileList);
        this.$refs.upload.fileList=[];
      //console.log(this.$refs.upload.fileList)
        this.src='';
      })
    },
    // 复制链接方法
    onCopy(e) {
      this.$message.success("复制成功");
    },
    onError(e) {
      this.$message.warning("该浏览器不支持自动复制");
    },
  },
};
</script>
<style lang='stylus' scoped>
a{
  text-decoration: none;
  color: #fff;
}
</style>
